﻿
using System;
using System.Collections.Generic;
using System.Data;
namespace AssettDatabase.BLL
{
    class Supplier
    {
        public bool Add(string Supplier_Name, string Supplier_Phone, string Sup_Primary_Contact_FN, string Sup_Primary_Contact_LN, string Sup_Primary_Contact_EML,
                        string Supplier_Website, string Sup_Web_Username, string Sup_Web_Password, string Supplier_Customer_Code,
                        string Sup_Comments)
        {
            DAL.Supplier mSupplier = new DAL.Supplier();
            return mSupplier.Add(Supplier_Name, Supplier_Phone, Sup_Primary_Contact_FN, Sup_Primary_Contact_LN, Sup_Primary_Contact_EML,
                       Supplier_Website, Sup_Web_Username, Sup_Web_Password, Supplier_Customer_Code,
                        Sup_Comments);
        }

        public bool Update(string Supplier_Name, string Supplier_Phone, string Sup_Primary_Contact_FN, string Sup_Primary_Contact_LN, string Sup_Primary_Contact_EML,
                        string Supplier_Website, string Sup_Web_Username, string Sup_Web_Password, string Supplier_Customer_Code,
                        string Sup_Comments, int Supplier_ID)
        {
            DAL.Supplier mSupplier = new DAL.Supplier();
            return mSupplier.Update(Supplier_Name, Supplier_Phone, Sup_Primary_Contact_FN, Sup_Primary_Contact_LN, Sup_Primary_Contact_EML,
                       Supplier_Website, Sup_Web_Username, Sup_Web_Password, Supplier_Customer_Code,
                        Sup_Comments, Supplier_ID);
        }

        public bool Del(int Supplier_ID)
        {
            DAL.Supplier mSupplier = new DAL.Supplier();
            return mSupplier.Del(Supplier_ID);
        }
        public List<VO.Supplier> GetSupplier()
        {
            List<VO.Supplier> mList = new List<VO.Supplier>();
            DAL.Supplier mSupplier = new DAL.Supplier();
            DataTable mDataTable = mSupplier.GetSupplier();

            foreach (DataRow dr in mDataTable.Rows)
            {
                VO.Supplier voSupplier = new VO.Supplier();
                voSupplier.Sup_Comments = System.Text.Encoding.Default.GetString((byte[])dr["Sup_Comments"]);
                voSupplier.Sup_Primary_Contact_EML = dr["Sup_Primary_Contact_EML"].ToString();
                voSupplier.Sup_Primary_Contact_FN = dr["Sup_Primary_Contact_FN"].ToString();
                voSupplier.Sup_Primary_Contact_LN = dr["Sup_Primary_Contact_LN"].ToString();
                voSupplier.Sup_Web_Password = dr["Sup_Web_Password"].ToString();
                voSupplier.Sup_Web_Username = dr["Sup_Web_Username"].ToString();
                voSupplier.Supplier_Customer_Code = dr["Supplier_Customer_Code"].ToString();
                voSupplier.Supplier_ID = Convert.ToInt32(dr["Supplier_ID"].ToString());
                voSupplier.Supplier_Name = dr["Supplier_Name"].ToString();
                voSupplier.Supplier_Phone = dr["Supplier_Phone"].ToString();
                voSupplier.Supplier_Website = dr["Supplier_Website"].ToString();

                mList.Add(voSupplier);
            }

            return mList;
        }

        public List<VO.Supplier> GetSupplierById(int Supplier_ID)
        {
            List<VO.Supplier> mList = new List<VO.Supplier>();
            DAL.Supplier mSupplier = new DAL.Supplier();
            DataTable mDataTable = mSupplier.GetSupplierById(Supplier_ID);

            foreach (DataRow dr in mDataTable.Rows)
            {
                VO.Supplier voSupplier = new VO.Supplier();
                voSupplier.Sup_Comments = System.Text.Encoding.Default.GetString((byte[])dr["Sup_Comments"]).ToString();
                voSupplier.Sup_Primary_Contact_EML = dr["Sup_Primary_Contact_EML"].ToString();
                voSupplier.Sup_Primary_Contact_FN = dr["Sup_Primary_Contact_FN"].ToString();
                voSupplier.Sup_Primary_Contact_LN = dr["Sup_Primary_Contact_LN"].ToString();
                voSupplier.Sup_Web_Password = dr["Sup_Web_Password"].ToString();
                voSupplier.Sup_Web_Username = dr["Sup_Web_Username"].ToString();
                voSupplier.Supplier_Customer_Code = dr["Supplier_Customer_Code"].ToString();
                voSupplier.Supplier_ID = Convert.ToInt32(dr["Supplier_ID"].ToString());
                voSupplier.Supplier_Name = dr["Supplier_Name"].ToString();
                voSupplier.Supplier_Phone = dr["Supplier_Phone"].ToString();
                voSupplier.Supplier_Website = dr["Supplier_Website"].ToString();

                mList.Add(voSupplier);
            }

            return mList;
        }

        public List<VO.Supplier> GetSupplierByName(string Supplier_Name)
        {
            List<VO.Supplier> mList = new List<VO.Supplier>();
            DAL.Supplier mSupplier = new DAL.Supplier();
            DataTable mDataTable = mSupplier.GetSupplierByName(Supplier_Name);

            foreach (DataRow dr in mDataTable.Rows)
            {
                VO.Supplier voSupplier = new VO.Supplier();
                voSupplier.Sup_Comments = System.Text.Encoding.Default.GetString((byte[])dr["Sup_Comments"]).ToString();
                voSupplier.Sup_Primary_Contact_EML = dr["Sup_Primary_Contact_EML"].ToString();
                voSupplier.Sup_Primary_Contact_FN = dr["Sup_Primary_Contact_FN"].ToString();
                voSupplier.Sup_Primary_Contact_LN = dr["Sup_Primary_Contact_LN"].ToString();
                voSupplier.Sup_Web_Password = dr["Sup_Web_Password"].ToString();
                voSupplier.Sup_Web_Username = dr["Sup_Web_Username"].ToString();
                voSupplier.Supplier_Customer_Code = dr["Supplier_Customer_Code"].ToString();
                voSupplier.Supplier_ID = Convert.ToInt32(dr["Supplier_ID"].ToString());
                voSupplier.Supplier_Name = dr["Supplier_Name"].ToString();
                voSupplier.Supplier_Phone = dr["Supplier_Phone"].ToString();
                voSupplier.Supplier_Website = dr["Supplier_Website"].ToString();

                mList.Add(voSupplier);
            }

            return mList;
        }
    }
}
